package com.cheng.im.service.friendship.controller;

import com.cheng.im.service.common.resp.CommonResult;
import com.cheng.im.service.friendship.service.ImFriendshipGroupMemberService;
import com.cheng.im.service.friendship.service.ImFriendshipGroupService;
import com.cheng.im.service.frienship.model.req.AddFriendShipGroupMemberReq;
import com.cheng.im.service.frienship.model.req.AddFriendShipGroupReq;
import com.cheng.im.service.frienship.model.req.DeleteFriendShipGroupMemberReq;
import com.cheng.im.service.frienship.model.req.DeleteFriendShipGroupReq;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * todo: 有bug
 */
@Api(tags = "好友分组")
@RestController
@RequestMapping("v1/friendship/group")
public class ImFriendshipGroupController {
    @Resource
    ImFriendshipGroupService imFriendShipGroupService;

    @Resource
    ImFriendshipGroupMemberService imFriendShipGroupMemberService;

    /**
     * 添加好友分组
     * @param req
     * @return
     */
    @ApiOperation(value = "新增好友分组")
    @PostMapping("/add")
    public CommonResult add(@RequestBody @Validated AddFriendShipGroupReq req)  {
        return imFriendShipGroupService.addGroup(req);
    }

    /**
     * 删除好友分组
     * @param req
     * @return
     */
    @DeleteMapping("/del")
    @ApiOperation(value = "删除好友分组")
    public CommonResult del(@RequestBody @Validated DeleteFriendShipGroupReq req)  {
        return imFriendShipGroupService.deleteGroup(req);
    }

    /**
     * 添加好友到分组
     * @param req
     * @return
     */
    @PostMapping("/member/add")
    @ApiOperation(value = "添加好友到分组")
    public CommonResult memberAdd(@RequestBody @Validated AddFriendShipGroupMemberReq req)  {
        return imFriendShipGroupMemberService.addGroupMember(req);
    }

    /**
     * 删除分组里面的好友
     * @param req
     * @return
     */
    @DeleteMapping("/member/del")
    @ApiOperation(value = "移除分组好友")
    public CommonResult memberdel(@RequestBody @Validated DeleteFriendShipGroupMemberReq req)  {
        return imFriendShipGroupMemberService.delGroupMember(req);
    }

}
